package com.example.testapplication.Paging;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.paging.PagedList;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import com.example.testapplication.R;

public class xueJetpackPiging extends AppCompatActivity {
    RecyclerView recyclerView;
    PageListAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xue_jetpack_piging);

        recyclerView = findViewById(R.id.recyclerView);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(RecyclerView.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);

        recyclerView.setAdapter(mAdapter=new PageListAdapter(this));

        IncomeViewModel incomeViewModel = new ViewModelProvider(this,new ViewModelProvider.NewInstanceFactory()).get(IncomeViewModel.class);
        incomeViewModel.getPagedListLiveData().observe(this, new Observer<PagedList<Income>>() {
            @Override
            public void onChanged(PagedList<Income> list) {
                mAdapter.submitList(list);
            }
        });
    }
}